package io.babystar.modules.app.controller;

import io.babystar.common.utils.DateUtils;
import io.babystar.common.utils.R;
import io.babystar.modules.app.dto.StudentDayCourseDateDto;
import io.babystar.modules.business.entity.ShopEntity;
import io.babystar.modules.business.service.CourseDateService;
import io.babystar.modules.business.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author jeson
 * @email 574197743@qq.com
 * @date 2021-03-23 20:03:34
 */
@RestController
@Api("周日课表接口")
@RequestMapping("app/appointmentcurriculum")
public class AppointmentCurriculumRest {
    @Autowired
    private ShopService shopService;
    @Autowired
    private CourseDateService courseDateService;

    /**
     * 根据条件查询所有店铺列表
     */
    //@Login
    @ApiOperation("根据条件查询所有店铺列表")
    @PostMapping("/allshoplist")
    public R allShopList(@RequestBody Map<String, Object> params){
        List<ShopEntity> shops = shopService.selectList(params);

        return R.ok().put("shops", shops);
    }

    /**
     * 日课表
     * courseDate 到天日期
     */
    //@Login
    @ApiOperation("日课表")
    @PostMapping("/schooldaytimetable")
    public R schoolDayTimetable(@RequestBody Map<String, Object> params){
        List<StudentDayCourseDateDto> studentDayCourseDates = courseDateService.studentDayCourseDate(params);

        return R.ok().put("studentDayCourseDates", studentDayCourseDates);
    }

    /**
     * 周课表
     * startDate 开始日期
     * endDate 结束日期
     */
    //@Login
    @ApiOperation("周课表")
    @PostMapping("/schoolweektimetable")
    public R schoolWeekTimetable(@RequestBody Map<String, Object> params){
        List<List<StudentDayCourseDateDto>> lists = courseDateService.schoolWeekTimetable(params);

        return R.ok().put("weekCurriculums", lists);
    }


    @ApiOperation("日课表")
    @PostMapping("/dayCourseDate")
    public R dayCourseDate(@RequestBody Map<String, Object> params){
        List<StudentDayCourseDateDto> studentDayCourseDates = courseDateService.dayCourseDate(params);

        return R.ok().put("studentDayCourseDates", studentDayCourseDates);
    }

    @ApiOperation("获取未来7天的日期")
    @GetMapping("/getFutureOneWeekDate")
    public R getFutureOneWeekDate() {
        List<String> list = DateUtils.getFutureDate();
        List<Map<String, String>> week = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, String> map = new HashMap<String, String>();
            String day = list.get(i);
            //2022-06-13 星期一
            map.put("dayWeek", day);
            //2022-06-13
            map.put("dayStr", day.substring(0,10));
            //Mon
            map.put("weekEn", DateUtils.weekToEn(day.substring(11,14)));
            //显示日
            map.put("day", day.substring(8, 10));
            //显示周
            if(i==0){
                map.put("week", "今天");
            }else if(i==1){
                map.put("week", "明天");
            } else{
                map.put("week", "周" + day.substring(13, 14));
            }
            map.put("today", DateUtils.getCurrentDay());
            week.add(map);
        }
        return R.ok().put("futureOneWeekDate", week);
    }

}
